﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Globalization;
using System.Threading;

namespace mal.Web.Routing
{
    public class LocalizedPage:Page
    {
        protected string cultureKey = "culture";
        private static CultureInfo defaultCulture;

        public static CultureInfo DefaultCulture
        {
            get { return LocalizedPage.defaultCulture; }
            set { LocalizedPage.defaultCulture = value; }
        }

        protected override void InitializeCulture()
        {
            base.InitializeCulture();
            try
            {
                if (PageRouteHandler.QueryString.ContainsKey(cultureKey))
                {
                    CultureInfo culture = new CultureInfo(PageRouteHandler.QueryString[cultureKey].ToString());
                    Thread.CurrentThread.CurrentCulture = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
                }
                else
                {
                    if (DefaultCulture != null)
                    {
                        Thread.CurrentThread.CurrentCulture = DefaultCulture;
                        Thread.CurrentThread.CurrentUICulture = DefaultCulture;
                    }
                }
            }
            catch
            {

            }
        }
    }
}
